home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / basic / matrix1.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  918b  |  57 lines

  1. #include <LEDA/matrix.h>
  2.  
  3. main()
  4.  
  5.   int d = read_int("dimension = ");
  6.  
  7.   matrix       A(d,d);
  8.   matrix       I(d,d);
  9.   double       det;
  10.  
  11.  
  12.   init_random();
  13.  
  14.   for(int i=0;i<d;i++)
  15.     for(int j=0;j<d;j++)
  16.       A(i,j) = double(random(-1000,1000))/100;
  17.  
  18.   float T = used_time();
  19.  
  20.  
  21.   cout << "A.inv():  ";
  22.   cout.flush();
  23.   I =  A.inv();
  24.   cout << string("%5.2f sec\n",used_time(T));
  25.  
  26.   cout << "A.det():  ";
  27.   cout.flush();
  28.   det = A.det();
  29.   cout << string("%5.2f sec \n",used_time(T));
  30.   newline;
  31.  
  32. /*
  33.   cout << "A*A.inv() = \n" << A*I << "\n";
  34.   newline;
  35. */
  36.  
  37.   while (Yes("A.solve(v) ? "))
  38.   {
  39.     vector v(d), x(d), y(d);
  40.  
  41.     for(int i=0;i<d;i++) v[i] = double(random(-1000,1000))/100;
  42.     
  43.     used_time(T);
  44.     x = A.solve(v);
  45.     cout << string("time for solve:  %5.2f \n",used_time(T));
  46.     newline;
  47.  
  48.     cout << "v   = " << v   << "\n";
  49.     cout << "A*x = " << A*x << "\n";
  50.     newline;
  51.   }
  52.  
  53.   return 0;
  54.  
  55. }
  56.